/**
 * Created by chenzheyu on 2017/4/10.
 */
var id=window.data.id;
$(function () {
    var IdIsPositive=$('#IdIsPositive');
    var IdIsOpposite=$('#IdIsOpposite');
    var DrivingLicence=$('#DrivingLicence');
    var option={

    };

    $.ajax({
       url:ctx+'/information/selectById' ,
        data:{
           id:id,
        },
        type:'GET',
        success:function (data) {

            var Dtat=data;
            option.id=Dtat.id;
            var url=Dtat.photourl.split('&:&');
            $('.IdIsPositive_img').prop('src',url[0]);
            $('.IdIsPositive_img_specimen').prop('src',url[0]);
            $('.IdIsOpposite_img').prop('src',url[1]);
            $('.IdIsOpposite_img_specimen').prop('src',url[1]);
            $('.DrivingLicence_img').prop('src',url[2]);
            $('.DrivingLicence_img_specimen').prop('src',url[2]);
            $('.IdentityCardFrontState').text(Dtat.idcardpositiveresult==1?'通过':'未通过');
            $('.IdIsOppositeState').text(Dtat.idcardbackresult==1?'通过':'未通过');
            $('.DrivingLicenceState').text(Dtat.driverresult==1?'通过':'未通过');
            $('.IdentityCardFrontRemark').text(Dtat.idcardpositiveremarks?Dtat.idcardpositiveremarks:'无');
            $('.IdIsOppositeRemark').text(Dtat.idcardbackremarks?Dtat.idcardbackremarks:'无');
            $('.DrivingLicenceRemark').text(Dtat.driverremarks?Dtat.driverremarks:'无');
            $('.name').text(Dtat.name);
            $('.IDNumber').text(Dtat.idcard);
            $('.drivernumber').text(Dtat.drivernumber);

            $('#IdIsPositive .miaoshu span').text(Dtat.idcard);
            $('#DrivingLicence .miaoshu span').text(Dtat.idcard);

            IdIsPositive.find('.idcardpositiveremarks').val(Dtat.idcardpositiveremarks);//正面
            IdIsOpposite.find('.idcardbackremarks').val(Dtat.idcardbackremarks);//反面
            DrivingLicence.find('.driverremarks').val(Dtat.driverremarks);//驾驶证


            if(Dtat.idcardpositiveresult==1){
                IdIsPositive.find('.Action .StateInputPass').attr('checked','checked').prop('checked',true)
            }else {
                IdIsPositive.find('.Action .StateInputNoPass').attr('checked','checked').prop('checked',true)
            }
            if(Dtat.idcardbackresult==1){
                IdIsOpposite.find('.Action .StateInputPass').attr('checked','checked').prop('checked',true)
            }else {
                IdIsOpposite.find('.Action .StateInputNoPass').attr('checked','checked').prop('checked',true)
            }

            if(Dtat.driverresult==1){
                DrivingLicence.find('.Action .StateInputPass').attr('checked','checked').prop('checked',true)
            }else {
                DrivingLicence.find('.Action .StateInputNoPass').attr('checked','checked').prop('checked',true)
            }


            function getLocalTime(nS) {
                return new Date(parseInt(nS) * 1000).toLocaleString().replace(/年|月/g, "-").replace(/日/g, " ");
            };
            $('.registrationtime').text(getLocalTime(Dtat.registrationtime))
        }
    });

    $('#IdIsPositive .StateInputPass').on('click',function () {
        $(this).attr('checked','checked').prop('checked',true);
        $('#IdIsPositive .StateInputNoPass').removeAttr('checked').prop('checked',false)
    });
    $('#IdIsPositive .StateInputNoPass').on('click',function () {
        $(this).attr('checked','checked').prop('checked',true);
        $('#IdIsPositive .StateInputPass').removeAttr('checked').prop('checked',false)
    });
    $('#IdIsOpposite .StateInputPass').on('click',function () {
        $(this).attr('checked','checked').prop('checked',true);
        $('#IdIsOpposite .StateInputNoPass').removeAttr('checked').prop('checked',false)
    });
    $('#IdIsOpposite .StateInputNoPass').on('click',function () {
        $(this).attr('checked','checked').prop('checked',true);
        $('#IdIsOpposite .StateInputPass').removeAttr('checked').prop('checked',false)
    });
    $('#DrivingLicence .StateInputPass').on('click',function () {
        $(this).attr('checked','checked').prop('checked',true);
        $('#DrivingLicence .StateInputNoPass').removeAttr('checked').prop('checked',false)
    });
    $('#DrivingLicence .StateInputNoPass').on('click',function () {
        $(this).attr('checked','checked').prop('checked',true);
        $('#DrivingLicence .StateInputPass').removeAttr('checked').prop('checked',false)
    });


    $('.IdIsPositive_button').on('click',function () {
        var src=$(this).siblings('img').eq(0).attr("src");

        IdIsPositive.find(' .OK').on('click',function () {
            $('.IdentityCardFrontState').text(IdIsPositive.find('.Action input[checked="checked"]').val());
            $('.IdentityCardFrontRemark').text(IdIsPositive.find('.beizhu input').val());

            $(' .Close').click();
        })

    });
    $('.IdIsOpposite_button').on('click',function () {
        var src=$(this).siblings('img').eq(0).attr("src");

        IdIsOpposite.find(' .OK').on('click',function () {
            $('.IdIsOppositeState').text(IdIsOpposite.find('.Action input[checked="checked"]').val());
            $('.IdIsOppositeRemark').text(IdIsOpposite.find('.beizhu input').val());

            $(' .Close').click();
        })

    });
    $('.DrivingLicence_button').on('click',function () {
        var src=$(this).siblings('img').eq(0).attr("src");

        DrivingLicence.find(' .OK').on('click',function () {
            $('.DrivingLicenceState').text(DrivingLicence.find('.Action input[checked="checked"]').val());
            $('.DrivingLicenceRemark').text(DrivingLicence.find('.beizhu input').val());

            $(' .Close').click();
        })

    });

    $('.Ok-Button').on('click',function () {
        option.idcardpositiveresult=IdIsPositive.find('.Action input[checked="checked"]').val()==='通过'?1:0;
        option.idcardpositiveremarks=IdIsPositive.find('.beizhu input').val();
        option.idcardbackresult=IdIsOpposite.find('.Action input[checked="checked"]').val()==='通过'?1:0;
        option.idcardbackremarks=IdIsOpposite.find('.beizhu input').val();
        option.driverresult=DrivingLicence.find('.Action input[checked="checked"]').val()==='通过'?1:0;
        option.driverremarks=DrivingLicence.find('.beizhu input').val();
        $.ajax({
            url:ctx+'/information/updateInforMation',
            data:option,
            type:'POST',
            success:function (data) {
                if(data.message=="修改成功"){
                    $('body').Overlays({data:{text:"审核保存成功，即将跳转页面！",state:"Ok"}});
                    setInterval(function () {
                        window.location.href=ctx+'/information/list';
                    },2000);
                }else {
                    $('body').Overlays({data:{text:"审核保存失败，请稍后重试！",state:"No"}});
                }
                
            }
        })
    })
    $('.cancel-Button').on('click',function(){
    	  	window.location.href=ctx+'/information/list'; 
    })
});